# coding: utf-8
""" 一维数组的索引：
		与Python的列表索引功能相似
	多维数组的索引：
		arr[r1:r2, c1:c2]
		arr[1,1] 等价 arr[1][1]
		[:] 代表某个维度的数据
"""
import numpy as np
from helpers import print_20_

print("01.ndarray的基本索引")
x = np.array([[1,2],[3,4],[5,6]])
print("打印x[0] ->", x[0])
print("普通python数组的索引, 打印x[0][1] ->", x[0][1])
print("ndarray数组的索引, 打印x[0,1] ->", x[0,1])
x = np.array([[[1, 2], [3,4]], [[5, 6], [7,8]]])
y = x.copy()
z = x
print("print(x) ->", x) 
y[0,0,1] = 20
print("y[0,0,1] = 20, print(x[0,0,1]) ->", x[0,0,1]) 
print("y[0,0,1] = 20, print(y[0,0,1]) ->", y[0,0,1]) 
print("y[0,0,1] = 20, print(z[0,0,1]) ->", z[0,0,1])
z[0,0,1] = 200
print("z[0,0,1] = 200, print(x[0,0,1]) ->", x[0,0,1]) 
print("z[0,0,1] = 200, print(y[0,0,1]) ->", y[0,0,1]) 
print("z[0,0,1] = 200, print(z[0,0,1]) ->", z[0,0,1])
print_20_()

print("02.ndarray的切片")

x = np.array([1,2,3,4,5])
print("print(x) ->", x)
print("print(x[1:3]) ->", x[1:3])
print("print(x[0:4:2]) ->", x[0:4:2])

x = np.array([[1,2],[3,4],[5,6]])
print("print(x) ->", x)
print("print(x[:2]) ->", x[:2])
print("print(x[:2, 1]) ->", x[:2, 1])
print("print(x[:2, :1]) ->", x[:2, :1])

x[:2,:2] = 0 # 标量赋值
print("print(x) ->", x)
print("print(x[:2,:1]) ->", x[:2,:1])
x[:2, :1] = [[8], [9]] # 数组赋值
print("print(x) ->", x)
